/**
* 作者: clz
* 日期: 2025-04-10 21:21:27
* 备注: 联盟建筑表信息
*/
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common;
import com.motu.monstercity.server.game.base.CommonUtils;
import com.motu.monstercity.server.game.commondata.union.UnionBuildUpgrade;
import com.motu.monstercity.server.game.commondata.union.UnionMain;
import com.motu.monstercity.server.game.logic.UnionManager;
import com.motu.vertx.module.utility.toolset.TimeUtils;

import java.util.List;

public class UnionBuild extends UnionBuildModel {
	public UnionBuild() {
		super();
	}

	public UnionBuild(long unionId, int buildId) {
		putUnionId(unionId);
		putBuildId(buildId);
		putLevel(1);
	}

	public void addExp(int value) {
		super.addExp(value);
		int curExp = getExp();
		//判断是否可以升级
		UnionBuildUpgrade unionBuildUpgrade = UnionManager.getUnionBuildUpgrade(getBuildId(), getLevel());
		if (unionBuildUpgrade.getConsume() <= curExp) {
			//满足升级条件
			addLevel(1);
			putExp(curExp - unionBuildUpgrade.getConsume());
		}
	}

	public Common.PBUnionBuild.Builder takeInitBuilder() {
		Common.PBUnionBuild.Builder sb = super.takeInitBuilder();
		if (getBuildTime() > TimeUtils.getCurTime()) {
			List<UnionBuildUserAssistRecord> unionBuildUserAssistRecordList = UnionManager.getUnionBuildUserAssistRecordList(getUnionId(),getBuildId());
			for (UnionBuildUserAssistRecord unionBuildUserAssistRecord : unionBuildUserAssistRecordList) {
				sb.addAssistRecordList(unionBuildUserAssistRecord.takeRecordBuilder());
			}
		}
		return sb;
	}

	public Common.PBUnionBuild.Builder takeBuilder() {
		Common.PBUnionBuild.Builder sb = super.takeBuilder();
		if (getBuildTime() > TimeUtils.getCurTime()) {
			List<UnionBuildUserAssistRecord> unionBuildUserAssistRecordList = UnionManager.getUnionBuildUserAssistRecordList(getUnionId(),getBuildId());
			for (UnionBuildUserAssistRecord unionBuildUserAssistRecord : unionBuildUserAssistRecordList) {
				sb.addAssistRecordList(unionBuildUserAssistRecord.takeRecordBuilder());
			}
		}
		return sb;
	}

	// 判断该联盟建筑是否已经建造完成，只有建造完成才有对应的加成
	public boolean isBuildComplete() {
		if (getBuildTime() <= TimeUtils.getCurTime()) {
			return true;
		} else {
			return false;
		}
	}

	// 对哪个性格的商业建筑有加成
	public int takeEarnAddEffectType() {
		UnionBuildUpgrade unionBuildUpgrade = UnionManager.getUnionBuildUpgrade(getBuildId(), getLevel());
		if (unionBuildUpgrade == null) {
			return 0;
		}
		int[] array = CommonUtils.strToIntArray(unionBuildUpgrade.getEffectType());
		return array[0];//1;101002  第一个配置对应商业建筑的性格
	}

	// 对某个性格的商业建筑的加成值多少
	public int takeEarnAddEffectValue() {
		UnionBuildUpgrade unionBuildUpgrade = UnionManager.getUnionBuildUpgrade(getBuildId(), getLevel());
		if (unionBuildUpgrade == null) {
			return 0;
		}
		int[] array = CommonUtils.strToIntArray(unionBuildUpgrade.getEffectlUpValue());
		return array[0];//500;3  第一个配置对应商业建筑的性格,的加成值
	}
}
